﻿using Microsoft.EntityFrameworkCore;
using ProjectCore.Common;
using ProjectCore.Domain.DomainService;
using ProjectCore.Domain.Model.Entity;
using ProjectCore.Domain.Repository.Interfaces;
using ProjectCore.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace ProjectCore.Infrastructure.DomainService
{
    public class OrderDomainService : IOrderDomainService
    {
        private readonly IBaseRepository<Order> baseRepository;
        private readonly IBaseRepository<Site> sitebase;
        private readonly IBaseRepository<Pay> paybase;
        private readonly MyContext myContext;
        public OrderDomainService(IBaseRepository<Order> _baseRepository, MyContext _myContext, IBaseRepository<Site> _sitebase, IBaseRepository<Pay> _paybase)
        {
            baseRepository = _baseRepository;
            sitebase = _sitebase;
            paybase = _paybase;
            myContext = _myContext;
        }

        //反填
        public async Task<Order> GetOrder(int Id)
        {

            try
            {
                return await myContext.Orders.FindAsync(Id);
            }
            catch (Exception) { throw; }
        }


        //支付反填
        public async Task<Pay> GetPay(int Id)
        {
            try
            {
                return await myContext.Pays.FindAsync(Id);
            }
            catch (Exception) { throw; }
        }


        //其他设置反填
        public async Task<Site> GetSite(int Id)
        {
            try
            {
                return await myContext.Sites.FindAsync(Id);
            }
            catch (Exception) { throw; }
        }


        //批量发货
        public async Task<int> UptState(string Id)
        {
            try
            {
                Order order = myContext.Orders.Find(Id);
                order.State = 2;
                return await myContext.SaveChangesAsync();
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
